﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayBoardInfo.Server.Forms.CustomComponents
{
    class StartToolStripButton : ToolStripButton
    {
        public enum Status 
        { 
            Started, Stoped
        }

        public event EventHandler StatusChanged;

        private Status currentStatus = Status.Stoped;

        internal Status CurrentStatus
        {
            get { return currentStatus; }
            set 
            {
                currentStatus = value;
                StatusChanged(this, new EventArgs());
            }
        }

        public StartToolStripButton()
            : base()
        {
            this.Image = global::DisplayBoardInfo.Server.Properties.Resources.control;
            this.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.Name = "startButton";
            this.Size = new System.Drawing.Size(35, 35);
            this.Text = "Start";
            this.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
            this.Click += new EventHandler(StartToolStripButton_Click);
            this.StatusChanged += new EventHandler(StartToolStripButton_StatusChanged);
        }

        void StartToolStripButton_StatusChanged(object sender, EventArgs e)
        {
            if (currentStatus == Status.Started)
            {
                this.Text = "Stop";
                this.Image = global::DisplayBoardInfo.Server.Properties.Resources.control_stop_square;
                Logger.Logger.Message(Logger.LogMessageType.Info, "Uruchamianie serwera...");
            }
            else if (currentStatus == Status.Stoped)
            {
                this.Text = "Start";
                this.Image = global::DisplayBoardInfo.Server.Properties.Resources.control;
                Logger.Logger.Message(Logger.LogMessageType.Info, "Zatrzymywanie serwera...");
            }
        }

        void StartToolStripButton_Click(object sender, EventArgs e)
        {
            if (currentStatus == Status.Started) CurrentStatus = Status.Stoped;
            else if (currentStatus == Status.Stoped) CurrentStatus = Status.Started;
        }
    }
}
